/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.mcx.modules.generation.repository;

import com.mcx.modules.generation.domain.Account;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
* @website https://el-admin.vip
* @author mcx
* @date 2022-03-17
**/
public interface AccountRepository extends JpaRepository<Account, Integer>, JpaSpecificationExecutor<Account> {
    /**
     * 根据用户名查询
     * @param username 用户名
     * @return /
     */
    Account findByUsername(String username);

//    /**
//     * 根据邮箱查询
//     * @param email 邮箱
//     * @return /
//     */
//    Account findByEmail(String email);

    /**
     * 根据手机号查询
     * @param phone 手机号
     * @return /
     */
    Account findByPhone(String phone);

//    /**
//     * 修改密码
//     * @param username 用户名
//     * @param pass 密码
//     * @param lastPasswordResetTime /
//     */
//    @Modifying
//    @Query(value = "update account set password = ?2 , pwd_reset_time = ?3 where username = ?1",nativeQuery = true)
//    void updatePass(String username, String pass, Date lastPasswordResetTime);
//
//    /**
//     * 修改邮箱
//     * @param username 用户名
//     * @param email 邮箱
//     */
//    @Modifying
//    @Query(value = "update account set email = ?2 where username = ?1",nativeQuery = true)
//    void updateEmail(String username, String email);

    int countByUsernameAndPassword(@NotBlank String username, @NotBlank String password);
}